/**
 * Copyright (c) 2016 Lenovo Group
 * All Rights Reserved.
 * 
 * Project Name:lmrp-api
 * Create Time: 2016年1月31日 下午9:08:59
 */
package com.lenovo.lmrp.api.model.entity;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lenovo.sdc.framework.util.AttributeBean;
import com.lenovo.sdc.framework.util.CommonUtil;
import com.lenovo.sdc.framework.util.JSONHelper;

/**
 * 
 * @author wujin
 * @version v1.0
 */
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class AExtensePO implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column
    private String id;
    
    @Column
    private String extprops;
    
    @Transient
    @JsonIgnore
    private AttributeBean attributeBean;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getExtprops() {
        return extprops;
    }

    public void setExtprops(String extprops) {
        this.extprops = extprops;
    }
    
    @SuppressWarnings("unchecked")
    public AttributeBean getAttributeBean() {
        if (Objects.nonNull(attributeBean))
            return attributeBean;
        else if (CommonUtil.isNullOrEmpty(extprops))
            attributeBean = new AttributeBean();
        else {
            try {
                attributeBean = new AttributeBean(JSONHelper.fromJSON(extprops, Map.class));
                return attributeBean;
            }
            catch (Exception exp) {
                exp.getStackTrace();
                attributeBean = new AttributeBean();
            }
        }
        
        return attributeBean;
    }
}
